package org.vectrics.user;

import java.io.Serializable;


public class PhoneNumber implements Serializable {
	public static final long serialVersionUID = 823425214;
	
	private String number = null;

	public PhoneNumber(String numberStr) {
		this.setNumber(numberStr);
	}
	
	public PhoneNumber() {
		super();
	}

	/**
	 * @return Returns the number.
	 */
	public String getNumber() {
		return number;
	}

	public void setNumber(String number) {
		String temp = number;
		if (temp == null) {
			this.number = null;
		} else {
			// Remove everthing exception numbers from temp.
			String temp2 = "";
			char[] charArray = temp.toCharArray();
			for (int i = 0; i < charArray.length; i++) {
				char c = charArray[i];
				if ((c >= '0') && (c <= '9')) {
					temp2 += "" + c;
				}
			}
			this.number = temp2;
		}
		
	}

	private boolean phoneNumberIsAllZeros(String number) {
		boolean result = true;
		for (int i = 0; i < number.length(); i++) {
			if (number.charAt(i) == '0') {
				
			} else {
				result = false;
			}
		}
		return(result);
	}
	
	
	public String getFormattedNumber() {
/*		String formatNumber = "";
		if ((this.number != null) && (this.number.length() > 0)) {
			if (phoneNumberIsAllZeros(this.number) == false) {
				String temp = this.number.toString();
				while (temp.length() < 10) {
					temp = "0" + temp;
				}
				formatNumber = "(" + temp.substring(0, 3) + ")" + temp.substring(3, 6)
				  + "-" + temp.substring(6, 10);
			}
		}
		return(formatNumber);*/
		return this.number;
	}

	public String toString() {
		return(this.getFormattedNumber());
	}
	
	public boolean equals(Object object) {
		PhoneNumber otherPhoneNumber = (PhoneNumber)object;
		return(this.number.equals(otherPhoneNumber.number));
	}
}
